/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.teach.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.teach.entity.TeachDistributeCtfset;
import com.lczyfz.istep.modules.teach.service.TeachDistributeCtfsetService;

/**
 * 下发_ctf题目集中间表Controller
 * @author cqh
 * @version 2017-05-19
 */
@Controller
@RequestMapping(value = "${adminPath}/teach/teachDistributeCtfset")
public class TeachDistributeCtfsetController extends BaseController {

	@Autowired
	private TeachDistributeCtfsetService teachDistributeCtfsetService;
	
	@ModelAttribute
	public TeachDistributeCtfset get(@RequestParam(required=false) String id) {
		TeachDistributeCtfset entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = teachDistributeCtfsetService.get(id);
		}
		if (entity == null){
			entity = new TeachDistributeCtfset();
		}
		return entity;
	}
	
	@RequiresPermissions("teach:teachDistributeCtfset:view")
	@RequestMapping(value = {"list", ""})
	public String list(TeachDistributeCtfset teachDistributeCtfset, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TeachDistributeCtfset> page = teachDistributeCtfsetService.findPage(new Page<TeachDistributeCtfset>(request, response), teachDistributeCtfset); 
		model.addAttribute("page", page);
		return "modules/teach/teachDistributeCtfsetList";
	}

	@RequiresPermissions("teach:teachDistributeCtfset:view")
	@RequestMapping(value = "form")
	public String form(TeachDistributeCtfset teachDistributeCtfset, Model model) {
		model.addAttribute("teachDistributeCtfset", teachDistributeCtfset);
		return "modules/teach/teachDistributeCtfsetForm";
	}

	@RequiresPermissions("teach:teachDistributeCtfset:edit")
	@RequestMapping(value = "save")
	public String save(TeachDistributeCtfset teachDistributeCtfset, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, teachDistributeCtfset)){
			return form(teachDistributeCtfset, model);
		}
		teachDistributeCtfsetService.save(teachDistributeCtfset);
		addMessage(redirectAttributes, "保存下发_ctf题目集中间表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachDistributeCtfset/?repage";
	}
	
	@RequiresPermissions("teach:teachDistributeCtfset:edit")
	@RequestMapping(value = "delete")
	public String delete(TeachDistributeCtfset teachDistributeCtfset, RedirectAttributes redirectAttributes) {
		teachDistributeCtfsetService.delete(teachDistributeCtfset);
		addMessage(redirectAttributes, "删除下发_ctf题目集中间表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachDistributeCtfset/?repage";
	}

}